package com.airobot.robot.exception;

import com.airobot.robot.dto.ChatResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    // 处理所有未被捕获的异常
    @ExceptionHandler(Exception.class)
    public ResponseEntity<ChatResponse> handleAllExceptions(Exception ex) {
        ChatResponse errorResponse = new ChatResponse();
        errorResponse.setStatus("error");
        errorResponse.setError("服务器内部错误: " + ex.getMessage());

        return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
    }

    // 可以添加更多特定的异常处理方法
    // @ExceptionHandler(SpecificException.class)
    // public ResponseEntity<ChatResponse> handleSpecificException(SpecificException ex) {
    //     // 处理特定异常
    // }
}